//
//  UIButton+XHLKit.m
//  XHLKit
//
//  Created by qinyulun on 16/6/18.
//  Copyright © 2016年 leTian. All rights reserved.
//

#import "UIButton+XHLKit.h"
#import "UIImage+XHLKit.h"

@implementation UIButton (XHLKit)

+ (UIButton *)ButtonWithRect:(CGRect)rect
                       title:(NSString *)title
                  titleColor:(UIColor *)color
    BackgroundImageWithColor:(UIColor *)imageColor
                 clickAction:(SEL)clickAction
              viewController:(id)viewController
                   titleFont:(CGFloat)font contentEdgeInsets:(UIEdgeInsets )contentEdgeInsets;
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setTitle:title forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageWithColor:imageColor]
                      forState:UIControlStateNormal];
    [button setTitleColor:color forState:UIControlStateNormal];
    button.contentEdgeInsets=contentEdgeInsets;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    if (clickAction) {
        [button addTarget:viewController
                   action:clickAction
         forControlEvents:UIControlEventTouchUpInside];
    }
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 4;
    return button;
}

+ (UIButton *)ButtonWithRect:(CGRect)rect
                       title:(NSString *)title
                  titleColor:(UIColor *)color
    BackgroundImageWithColor:(UIColor *)imageColor
                 clickAction:(SEL)clickAction
              viewController:(id)viewController
                   titleFont:(CGFloat)font contentEdgeInsets:(UIEdgeInsets )contentEdgeInsets cornerRadius:(float)radius
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setTitle:title forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageWithColor:imageColor]
                      forState:UIControlStateNormal];
    [button setTitleColor:color forState:UIControlStateNormal];
    button.contentEdgeInsets=contentEdgeInsets;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    if (clickAction) {
        [button addTarget:viewController
                   action:clickAction
         forControlEvents:UIControlEventTouchUpInside];
    }
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = radius;
    return button;
}

+ (UIButton *)ButtonWithRect:(CGRect)rect
                       title:(NSString *)title
                  titleColor:(UIColor *)color
                 clickAction:(SEL)clickAction
                       image:(NSString *)image
              viewController:(id)viewController
                   titleFont:(CGFloat)font
             titleEdgeInsets:(UIEdgeInsets )titleEdgeInsets;
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setTitle:title forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setTitleColor:color forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    button.titleEdgeInsets=titleEdgeInsets;
    if (clickAction) {
        [button addTarget:viewController
                   action:clickAction
         forControlEvents:UIControlEventTouchUpInside];
    }
    
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 4;
    return button;
}


@end
